<aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">

        <!-- Sidebar user panel (optional) -->
        <div class="user-panel">
            <div class="pull-left image">
                <img src="{{ Admin::user()->avatar }}" class="img-circle" alt="User Image">
            </div>
            <div class="pull-left info">
                <p>{{ Admin::user()->name }}</p>
                <!-- Status -->
                <a href="#"><i class="fa fa-circle text-success"></i> {{ trans('admin.online') }}</a>
            </div>
        </div>

        @if(config('admin.enable_menu_search'))
        <!-- search form (Optional) -->
        <form class="sidebar-form" style="overflow: initial;" onsubmit="return false;">
            <div class="input-group">
                <input type="text" autocomplete="off" class="form-control autocomplete" placeholder="Search...">
              <span class="input-group-btn">
                <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
                </button>
              </span>
                <ul class="dropdown-menu" role="menu" style="min-width: 210px;max-height: 300px;overflow: auto;">
                    @foreach(Admin::menuLinks() as $link)
                    <li>
                        <a href="{{ admin_url($link['uri']) }}"><i class="fa {{ $link['icon'] }}"></i>{{ admin_trans($link['title']) }}</a>
                    </li>
                    @endforeach
                </ul>
            </div>
        </form>
        <!-- /.search form -->
        @endif

        <!-- Sidebar Menu -->
        <ul class="sidebar-menu">
            <li class="header">{{ trans('admin.menu') }}</li>

            @each('admin::partials.menu', Admin::menu(), 'item')

        </ul>
        <!-- /.sidebar-menu -->
    </section>
    <!-- /.sidebar -->
</aside>
<input type="hidden" id="admin_id" value="{{Admin::user()->id}}">
<link rel="stylesheet" href="/im/layui/css/layui.css" media="all">
<script src="/im/layui/layui.js"></script>
<script src="/im/socket.js"></script>

<script>
    layui.use('layim', function (layim) {
        var id = $('#admin_id').val();
        var config = {
            url: 'ws://47.106.117.232:9503',
            open: (ws) => {
                ws.send(JSON.stringify({
                    type: 'online',
                    data: {
                        id: id
                    }
                }));
                //发送消息
                layim.on('sendMessage', function (res) {
                    var mine = res.mine; //包含我发送的消息及我的信息
                    var to = res.to; //对方的信息
                    ws.send(JSON.stringify({
                        type: 'sendMessage', //随便定义，用于在服务端区分消息类型
                        data: res
                    }));
                });
            },
            msg: (data) => {
                var res = JSON.parse(data);
                console.log(res);
                //初始化ini
                if (res.type == 'setIni') {
                    layim.config({
                        init: res.data,
                        //获取群员接口（返回的数据格式见下文）
                        members: {
                            url: 'http://www.huaying90.com:88/api/group/users', //接口地址（返回的数据格式见下文）
                            type: 'get', //默认get，一般可不填
                            data: {} //额外参数
                        },
                        //上传图片接口（返回的数据格式见下文），若不开启图片上传，剔除该项即可
                        uploadImage: {
                            url: 'http://www.huaying90.com:88/api/upload',  //接口地址
                            type: 'post' //默认post
                        }
                    });
                }
                //收到消息
                else if(res.type == 'sendMessage'){
                    layim.getMessage(res.data);
                }
                //好友状态
                else if(res.type == 'onlineStatus'){
                    if(res.data.status){
                        layim.setFriendStatus(res.data.id, 'online');
                    }else{
                        layim.setFriendStatus(res.data.id, 'offline');
                    }
                }
                else {
                }
            }
        };
        socketLink(config)
    });

</script>


